package com.situ.mall.admin.interceptor;

import com.situ.mall.common.util.RequestUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//登录拦截器
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object o = RequestUtil.getCurrent();
        if (o == null) {
            //不是ajax重定向
                response.sendRedirect("/login");
            //是ajax就返回401错误码
            return false;
        } else {
            return true;
        }

    }
}
